Question 1


In [1]:
import math

class Activation:
    '''A math class
    '''
    
    def sigmoid(self, x):
        return 1 / (1 + math.exp(-x))
    
    def tanh(self, x):
        a, b = math.exp(x), math.exp(-x)
        return (a - b) / (a + b)
    
    def relu(self, x):
        return x if x >= 0 else 0
    
    def leaky_relu(self, alpha, x):
        return x if x >= 0 else alpha * x
    
    def elu(self, alpha, x):
        return x if x >= 0 else alpha * (math.exp(x) - 1)

activation = Activation()
print(activation.sigmoid(10))
print(activation.relu(20))
print(activation.tanh(-1))
print(activation.leaky_relu(0.1, -1))
print(activation.elu(0.1, -1))


0.9999546021312976
20
-0.7615941559557649
-0.1
-0.06321205588285576

Question 2


In [2]:
import os

def len(path):
    sum = 0
    for i in os.listdir(path):
        if os.path.isdir(path + os.path.sep + i):
            sum = sum + len(path + os.path.sep + i)
        else:
            sum = sum + 1
    return sum

print(len('face'))


69